/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package shellCommands;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author SOGOBA
 */
public class ShellSuperClass {
     private List<InterShell> _commandList = new ArrayList<InterShell>();
    private ContextCommande _context = new ContextCommande();
    private boolean stop = false;
    Scanner br;
    String line;

    public ShellSuperClass() {
        ContextCommande context = getContext();
        // add "category" command
        addCommand(new CategoryCommand(context));
                // add "cart" command
        addCommand(new CartCommand(context));
            // add "connect" command
        addCommand(new ConnectCommand(context));
          // add "currency" command
        addCommand(new CurrencyCommand(context));
       // add "customers" command
        addCommand(new CustomersCommand(context));
        // Add "help" command.
        addCommand(new HelpCommand(context,getCommands()));
           // add "language" command
        addCommand(new LanguageCommand(context));     
       // add "output" command
        addCommand(new OutputCommand(context));       
       // add product" command
        addCommand(new ProductCommand(context));        
        // Add "quit" command.
        addCommand(new QuitCommand());
      // add "store" command
        addCommand(new StoreCommand(context));
        // put the EBs' homes in the context
        context.setVar("PROMPT", "->");
        context.setVar("BANNER", getBanner());
   //     context.setVar("customerBean", customerBean);
   //     context.setVar("adminBean", adminBean);
    //    context.setVar("admin",admin);
//        context.setVar("shellMaster", this);
     //   context.setVar("cartLocal", cartLocal);
    }
   

    protected final ContextCommande getContext() {
        return _context;
    }
   
    protected final List<InterShell> getCommands(){
        return _commandList;
    }

    protected final void stop() {
        stop = true;
    }

   
       

    private String getBanner() {
        StringBuilder sb = new StringBuilder();
        sb.append("\n-------------------------------------------------");
        sb.append("\n|                 WINERY                        |");
        sb.append("\n|                                               |");
        sb.append("\n-------------------------------------------------");
        return sb.toString();
    }

  /**  protected final synchronized void removeCommand(String name) {
        out.println("Removing command  : " + name);
        _commandNameMap.remove(name);
    }**/

   

    protected final synchronized InterShell getCommand(String name) {
        InterShell sc=null;
        for(InterShell cmd : _commandList){
            if(cmd.getName().toString().equals(name)){
                sc=cmd;
            }      
        }

        return sc;
    }
    
    public List<InterShell> getCommandList(){
        return _commandList;
    }

        protected final synchronized void addCommand(InterShell sc) {
        _commandList.add(sc);
    }

    protected final synchronized void clearCommands() {
        _commandList.clear();
    }
}
